<template>
  <div>
    <yf-search>
      <yf-search-body>
        <a-form>
          <a-form-item label="选择查询类型">
            <a-select v-model="search.type" @select="setupTransferModal">
              <a-select-option :value="0">按公司查询</a-select-option>
              <a-select-option :value="1">按门店查询</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="选择公司/门店">
            <a-input v-model="search.storeCode" readonly="true" @click="showTransferModal" placeholder="单行输入"></a-input>
          </a-form-item>
          <a-form-item label="商品信息">
            <a-input v-model="search.productCode" readonly="true" placeholder="商品名称/商品编码"></a-input>
          </a-form-item>
          <a-form-item label="时间：">
            <a-range-picker  v-model:value="search.rangeTime" />
          </a-form-item>
        </a-form>
      </yf-search-body>
      <yf-search-action>
        <a-button @click="exportFiles">导出</a-button>
      </yf-search-action>
    </yf-search>
    <a-card>
       <a-button type="primary">导入</a-button>
      <a-button type="primary">删除</a-button>
    </a-card>
    <a-table>
      <a-table-column title="序号" key="index" ></a-table-column>
      <a-table-column title="公司名称" key="index" ></a-table-column>
      <a-table-column title="公司编号" key="index" ></a-table-column>
      <a-table-column title="门店名称" key="index" ></a-table-column>
      <a-table-column title="门店编码" key="index" ></a-table-column>
      <a-table-column title="商品编码" key="index" ></a-table-column>
      <a-table-column title="商品名称" key="index" ></a-table-column>
      <a-table-column title="品类二级" key="index" ></a-table-column>
      <a-table-column title="采购三级" key="index" ></a-table-column>
      <a-table-column title="单限购数量" key="index" ></a-table-column>
      <a-table-column title="规则名称" key="index" ></a-table-column>
      <a-table-column title="规则状态" key="index" ></a-table-column>
      <a-table-column title="创建时间" key="index" ></a-table-column>
      <a-table-column title="操作人" key="index" ></a-table-column>
      <a-table-column title="操作" key="index" ></a-table-column>
    </a-table>
    <yf-transfer-modal
        :title="transferData.title"
        :visible="transferData.transferVisible"
        :item="transferData.item"
        :params="transferData.params"
        :selectHierarchy="transferData.selectHierarchy"
        @ok="transferOk"
      @cancel="()=>{
        transferData.transferVisible = false;
      }"
      ></yf-transfer-modal>
    <UploadModal title="导入" :visible="updateVisible" @handleOk="updateOk"
     @handleCancel="updateCancel"></UploadModal>
  </div>
</template>
<script lang="ts">
import {reactive, toRefs, toRaw, onMounted} from "vue";
import { ConfirmBefore } from "@/utils/common";
//import TransferModal from "@/components/TransferModal/index";
import UploadModal from "./components/UploadModal/index.vue";
import YfTransferModal from "@/components/TransferModal/index.vue";


const confirmDel = ()=> {
  return new Promise((resolve) => {
    this.$confirm({
      title: "删除",
      content: `<p>当前商品已被部分规则启用，且规则处于开启状态，删除后将无法恢复， 确定删除吗？</p>`,
    onOk() {
      resolve(true);
    },
    onCancel() {
      resolve(false);
    },
  })
  })
}
export default{
  components:{
    YfTransferModal,
    UploadModal
  },
  setup(){
    const state = reactive({
      search:{},
      treeData:[],
      updateVisible:false
    })

    const transferState = reactive({
      transferData:{
        title:"",
        item:[],
        selectHierarchy: "",
        transferVisible:false,
        params:{
          levelQuery: {
            storeCode: "",
            userCode: "00223705",
            orgCode: "",
            hierarchyList: ["01", "02", "03", "04", "06", "07"]},

        },
      }
    })
    const setupTransferModal = (value)=>{
      console.log("下啊飒飒是",value)
      transferState.transferData.title = value ==0?"选择公司":"选择门店";
      transferState.transferData.selectHierarchy=value==0?"01":"07";
      //transferState.transferData.transferVisible = true;
    }

    const transferOk = (selectKeys)=>{
      console.log("树选择",selectKeys);
      transferState.transferData.transferVisible = false;
    }

    const showTransferModal = ()=>{
      transferState.transferData.transferVisible=true
    }

    const exportFiles = ()=>{
      console.log("导出")
    }
    const updateOk = ()=>{
      updateCancel();
    }
    const updateCancel = ()=>{
      state.updateVisible = false;
    }

    onMounted(()=>{
      setupTransferModal(0);
      ConfirmBefore({msg:"他们都是傻逼",title:"删除"});
    })

    return {
      ...toRefs(state),
      ...toRefs(transferState),
      updateOk,
      updateCancel,
      showTransferModal,
      setupTransferModal,
      transferOk
    };
  }
}
</script>
